﻿using LanguagePolish.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LanguagePolish.Controls
{
    /// <summary>
    /// Логика взаимодействия для LessonsCalendar.xaml
    /// </summary>
    public partial class LessonsCalendar : UserControl
    {
        //TODO
        public DateTime FirstDay { get; set; }

        //TODO
        public DateTime LastDay { get; set; }

        public bool EnableMenu
        {
            set
            {
                weekCalendar.EnableMenu = value;
                monthCalendar.EnableMenu = value;
            }
        }

        public event EventHandler<AddLessonEventArgs> AddLesson
        {
            add 
            { 
                monthCalendar.Grid.AddLesson += value;
                weekCalendar.Grid.AddLesson += value;
            }
            remove
            {
                monthCalendar.Grid.AddLesson -= value;
                weekCalendar.Grid.AddLesson -= value;
            }
        }

        public event EventHandler<EditLessonEventArgs> EditLesson
        {
            add
            {
                monthCalendar.Grid.EditLesson += value;
                weekCalendar.Grid.EditLesson += value;
            }
            remove
            {
                monthCalendar.Grid.EditLesson -= value;
                weekCalendar.Grid.EditLesson -= value;
            }
        }

        public event EventHandler<RemoveLessonEventArgs> RemoveLesson
        {
            add
            {
                monthCalendar.Grid.RemoveLesson += value;
                weekCalendar.Grid.RemoveLesson += value;
            }
            remove
            {
                monthCalendar.Grid.RemoveLesson -= value;
                weekCalendar.Grid.RemoveLesson -= value;
            }
        }

        private ILessonsProvider lessonsProvider;

        public ILessonsProvider LessonsProvider
        {
            get { return lessonsProvider; }
            set 
            {
                lessonsProvider = value;
                monthCalendar.LessonsProvider = value;
                weekCalendar.LessonsProvider = value;
            }
        }

        public LessonsCalendar()
        {
            InitializeComponent();
            monthCalendar.SwitchMode += monthCalendar_SwitchMode;
            weekCalendar.SwitchMode += weekCalendar_SwitchMode;
        }

        public void Reload()
        {
            monthCalendar.RefreshGrid();
            weekCalendar.RefreshGrid();
        }

        void weekCalendar_SwitchMode(object sender, EventArgs e)
        {
            weekCalendar.Visibility = System.Windows.Visibility.Collapsed;
            monthCalendar.Visibility = System.Windows.Visibility.Visible;
        }

        void monthCalendar_SwitchMode(object sender, EventArgs e)
        {
            weekCalendar.Visibility = System.Windows.Visibility.Visible;
            monthCalendar.Visibility = System.Windows.Visibility.Collapsed;
        }
    }
}
